package com.aixingfu.sports.ui.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.WindowManager;
import android.widget.ImageView;

import com.aixingfu.sports.LoginActivity;
import com.aixingfu.sports.MainActivity;
import com.aixingfu.sports.R;
import com.orie.librarybase.base.BaseActivity;
import com.orie.librarybase.utils.UserUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
//欢迎页

public class WelcomeActivity extends BaseActivity {

    @BindView(R.id.iv_welcome_bg)
    ImageView ivWelcomeBg;

    @Override
    protected int provideContentViewId() {
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN ,
                WindowManager.LayoutParams. FLAG_FULLSCREEN);
        return R.layout.activity_welcome;

    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            String token = UserUtils.getToken(WelcomeActivity.this);
            if (TextUtils.isEmpty(token)) {
                LoginActivity.startActivityByRoute();
                finish();
            } else {
                MainActivity.startActivityByRoute();
                finish();
            }
            super.handleMessage(msg);
        }
    };

    @Override
    protected void initView(Bundle savedInstanceState) {
        ButterKnife.bind(this);
        ivWelcomeBg.setImageDrawable(getResources().getDrawable(R.drawable.qidong_bg)); //不会变形
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                    Message message = new Message();
                    message.what = 1;
                    handler.sendMessage(message);// 发送消息
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void beforeInit() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
